unit uniEnemyAircraft_Boss01;

interface

uses
  uniEnemyAircraft,
  Classes;

type
  { EnemyAircraft_Boss01 }

  EnemyAircraft_Boss01 = class(EnemyAircraft)
  public
    constructor Create(et: EnemyType; p: array of Single; randFact: Single = 1.0);
    destructor Destroy; override;

    procedure update; override;
    procedure init; overload; override;
    procedure init(p: array of Single; randFact: Single = 1.0); overload;override;
    procedure move;override;
  end;


implementation

uses
  uniConfig,
  uniGlobal;

{ EnemyAircraft_Boss01 }

constructor EnemyAircraft_Boss01.Create(et: EnemyType; p: array of Single; randFact: Single);
begin
  inherited Create(et, p, randFact);
  init(p, randFact);
end;

destructor EnemyAircraft_Boss01.Destroy;
begin
  inherited;
end;

//----------------------------------------------------------
// this is only here to get rid of the IRIX compiler warning...

procedure EnemyAircraft_Boss01.init;
begin
  inherited init;
end;

procedure EnemyAircraft_Boss01.init(p: array of Single; randFact: Single);
begin
  inherited init;

  damage := -10000.0 * uniGlobal.gameSkill;
  baseDamage := damage;
  size[0] := 2.6;
  size[1] := 2.3;
  collisionMove := 0.1;
  vel[1] := 0.02;
  age := 600;

end;

procedure EnemyAircraft_Boss01.move;
var
  _config: Config;
  hpos: PSingle;
  diff: array[0..1] of Single;
  approachDist: Single;
begin
  _config := uniConfig.instance;

  if Boolean(target) then
  begin
    hpos := target.getPos;
  end
  else
  begin
    hpos := @pos;
  end;
  diff[0] := hpos^; Inc(hpos);
  diff[1] := hpos^;

  if Boolean(Round((age + 25) / 512) mod 2) then
  begin
    approachDist := 9.0 * (2.0 - uniGlobal.gameSkill);
  end
  else
  begin
    approachDist := 12.0 * (2.0 - uniGlobal.gameSkill);
  end;

  if Abs(diff[1]) < (approachDist + 2.0 * sin(uniGlobal.frame * 0.05)) then
  begin
    diff[1] := diff[1] * diff[1] / approachDist;
  end;

  if Boolean(Round(age / 512) mod 2) then
  begin
    lastMoveX := (0.98 * lastMoveX) + (0.0010 * uniGlobal.gameSkill * diff[0]);
    lastMoveY := (0.98 * lastMoveY) + (0.0010 * uniGlobal.gameSkill * diff[1]);
  end
  else //-- release gnats
  begin
    lastMoveX := (0.90 * lastMoveX) + (0.0003 * uniGlobal.gameSkill * diff[0]);
    lastMoveY := (0.90 * lastMoveY) + (0.0010 * uniGlobal.gameSkill * diff[1]);
  end;

  pos[0] := pos[0] + uniGlobal.speedAdj * (lastMoveX);
  pos[1] := pos[1] + uniGlobal.speedAdj * (lastMoveY + vel[1]);

  if pos[0] < -_config.screenBoundX then pos[0] := -_config.screenBoundX;
  if pos[0] > _config.screenBoundX then pos[0] := _config.screenBoundX;

end;

//-- NOTE: Many of the firing rates are not adjusted by game->speedAdj
//-- so they will not be totally correct. Should be close enough for jazz, though.
//----------------------------------------------------------

procedure EnemyAircraft_Boss01.update;
var
  tmpAircraft: EnemyAircraft;
  hpos: PSingle;
  a: Single;
  s: Single;
  p: array[0..2] of Single;
begin
  tmpAircraft := nil;
  hpos := uniGlobal._hero.getPos;
  a := hpos^ - pos[0];

  //-- update age
  Inc(age);
  Dec(shootInterval);

  pos[0] := pos[0] + secondaryMove[0] * uniGlobal.speedAdj;
  pos[1] := pos[1] + secondaryMove[1] * uniGlobal.speedAdj;
  s := (1.0 - uniGlobal.speedAdj) + (uniGlobal.speedAdj * 0.7);
  secondaryMove[0] := secondaryMove[0] * s;
  secondaryMove[1] := secondaryMove[1] * s;
  move;

  p[0] := pos[0];
  p[1] := pos[1];
  p[2] := pos[2];

  if Abs(a) < 5.0 then
  begin
    shootVec[1] := -0.65;
    preFire := (age mod 6) / 6.0;
    if not Boolean(age mod 6) then
    begin
      shootSwap := Integer(not Boolean(shootSwap));
      if Boolean(shootSwap) then
      begin
        p[0] := pos[0] + 0.55;
        p[1] := pos[1] - 1.7;
        uniGlobal._enemyAmmo.addAmmo(0, p, shootVec);
        p[1] := p[1] + 0.5;
        uniGlobal._enemyAmmo.addAmmo(0, p, shootVec);
      end
      else
      begin
        p[0] := pos[0] - 1.22;
        p[1] := pos[1] - 1.22;
        uniGlobal._enemyAmmo.addAmmo(0, p, shootVec);
        p[1] := p[1] + 0.5;
        uniGlobal._enemyAmmo.addAmmo(0, p, shootVec);
      end;
    end;
  end
  else
  begin
    if preFire > 0.0 then
      preFire := preFire - 0.05
    else
      preFire := 0.0;
  end;

  //-- add Gnats
  if not Boolean(Round(age / 512) mod 2) then
  begin
    if not Boolean(Round(age / 64) mod 2) and not Boolean(age mod 4) then
    begin
      p[0] := p[0] + 1.7;
      p[1] := p[1] + 1.2;
      tmpAircraft := uniGlobal._itemAdd.dynamicEnemyAdd(EnemyGnat, p, uniGlobal.gameFrame + 2);
      tmpAircraft.over := Self;
      tmpAircraft.setTarget(Self);
    end;
  end;
end;

end.

